#ifndef _WS2812_H_
#define _WS2812_H_

#include <stdint.h>
#include <stdbool.h>

#include "iot_spi.h"

// X点数
#define WS2812_LED_X_MAX 10
// Y点数
#define WS2812_LED_Y_MAX 1
// 点阵个数
#define WS2812_LED_NUM (WS2812_LED_X_MAX * WS2812_LED_Y_MAX)

// spi模式--------------------------------------------------------------------------------------------------------
// rgb转spi数据位宽
#define SPI_DATA_BIT_WIDE 12
#if SPI_DATA_BIT_WIDE == 12
// spi 50/16=3.125M    (1/(3.125M/4))=1.28us
//  11111100  SIG_1   3/4 = 75%      960ns 320ns
//  11000000  SIG_0   1/4 = 25%      320ns 960ns
#define SIG_1 0X0E
#define SIG_0 0X08
#elif SPI_DATA_BIT_WIDE == 24
// spi 50/8=6.25M    (1/(6.25M/8))=1.28us
//  11111100  SIG_1   6/8 = 75%      960ns 320ns
//  11000000  SIG_0   2/8 = 25%      320ns 960ns
#define SIG_1 0XFC
#define SIG_0 0XC0
#endif

typedef uint8_t u8_buf[SPI_DATA_BIT_WIDE];

typedef struct RGB_Color {
    unsigned char B;
    unsigned char R;
    unsigned char G;
    unsigned char l;
} RGB_Color;

typedef struct HSV_Color {
    float H;
    float S;
    float V;
} HSV_Color;

typedef union {
    uint32_t v32;
    RGB_Color v8;
} rgb888_32_u;

/**
 * @brief Initialize the WS2812 LED driver using SPI.
 *
 * This function initializes the SPI interface for controlling WS2812 LEDs.
 *
 * @param id SPI device ID to use for communication.
 */
void ws281x_init(enum EnumSpiId id);

/**
 * @brief Set the on/off state of one or more WS2812 LEDs.
 *
 * This function updates the specified number of LEDs to the given on/off state.
 *
 * @param light_cnt Number of LEDs to update.
 * @param sta Boolean indicating whether to turn the LEDs on or off.
 */
void ws2812x_set_light_sta(int light_cnt, bool sta);
#endif
